﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Web.UI.WebControls;
using Class_Entity;
using BussinessObject;
using System.IO;


public partial class WebApplication_ADResume : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Convert.ToInt32(Session["RoleCode"]) != 2)
        {
            if (!Page.IsPostBack)
            {
                loadGrid();

            }
        }
        else
            Response.Redirect("ADAccounts.aspx");
    }
    private void loadGrid()
    {
        Users us = new Users();
        BOUsers bus = new BOUsers();

        GridView1.DataSource = bus.Load_Users(us);
        GridView1.DataBind();
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        Users us = new Users();
        BOUsers bus = new BOUsers();

        us.Username = txtSearch.Text;

        GridView1.DataSource = bus.Find_UserByUsername(us);
        GridView1.DataBind();
    }
    protected void btnShow_Click(object sender, EventArgs e)
    {
        loadGrid();
    }
    private void FileDownload(string filename)
    {
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
    Response.TransmitFile("~//WebApplication//Resume//UserResume//"+filename);
    }
    protected void GridView1_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
    {
        string s = GridView1.Rows[e.RowIndex].Cells[2].Text;
        if (!s.Equals(""))
        {
            FileDownload(s);
        }
    }
    protected void GridView1_SelectedIndexChanging(object sender, System.Web.UI.WebControls.GridViewSelectEventArgs e)
    {
        Session["email"] = GridView1.Rows[e.NewSelectedIndex].Cells[4].Text;
        Response.Redirect("ADSendEmail.aspx");
    }
}